using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;

namespace RegEdit
{
    public class RegistryEditor
    {
        // Members
        string m_strRegSubKey;
        RegistryKey m_WMEUtilitiesKey;

        public RegistryEditor(string strRegSubKey, RegistryKeyPermissionCheck regPermissions)
        {
            if (string.Empty == strRegSubKey)
                throw new Exception("Invalid registry sub-key");

            m_strRegSubKey = strRegSubKey;
            
            m_WMEUtilitiesKey = Registry.CurrentUser.CreateSubKey(m_strRegSubKey, regPermissions);
        }

        ~RegistryEditor()
        {
            m_WMEUtilitiesKey.Close();
        }

        public string ReadRegistryKeyValue(string strKey, string strDefaultValue)
        {
            return m_WMEUtilitiesKey.GetValue(strKey, strDefaultValue).ToString();
        }

        public void WriteRegistryKeyValue(string strKey, string strValue)
        {
            //RegistryPermission regPermission = new RegistryPermission(RegistryPermissionAccess.AllAccess, "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion");
            //regPermission.Demand();
            m_WMEUtilitiesKey.SetValue(strKey, strValue, RegistryValueKind.String);
        }
    }
}
